package com.zzl.zzloj.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzl.zzloj.annotation.AuthCheck;
import com.zzl.zzloj.common.BaseResponse;
import com.zzl.zzloj.common.ErrorCode;
import com.zzl.zzloj.common.ResultUtils;
import com.zzl.zzloj.constant.UserConstant;
import com.zzl.zzloj.exception.BusinessException;
import com.zzl.zzloj.judge.JudgeService;

import com.zzl.zzloj.model.dto.questionsubmit.QuestionSubmitAddRequest;
import com.zzl.zzloj.model.dto.questionsubmit.QuestionSubmitQueryRequest;

import com.zzl.zzloj.model.entity.QuestionSubmit;
import com.zzl.zzloj.model.entity.User;
import com.zzl.zzloj.model.vo.QuestionSubmitVO;
import com.zzl.zzloj.service.QuestionSubmitService;
import com.zzl.zzloj.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 题目提交接口
 *
 * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
 * @from <a href="https://yupi.icu">编程导航知识星球</a>
 */
//@RestController
@RequestMapping("/question_submit")
@Slf4j
@Deprecated
public class QuestionSubmitController {

    @Resource
    private QuestionSubmitService questionSubmitService;

    @Resource
    private UserService userService;

    @Resource
    private JudgeService judgeService;
    ///**
    // * 提交题目
    // * @param questionSubmitAddRequest
    // * @param request
    // * @return
    // */
    //@PostMapping("/")
    //public BaseResponse<Long> doQuestionSubmit(@RequestBody QuestionSubmitAddRequest questionSubmitAddRequest,
    //        HttpServletRequest request) {
    //    if (questionSubmitAddRequest == null || questionSubmitAddRequest.getQuestionId() <= 0) {
    //        throw new BusinessException(ErrorCode.PARAMS_ERROR);
    //    }
    //    // 登录才能提交题目
    //    final User loginUser = userService.getLoginUser(request);
    //    long questionSubmitId = questionSubmitService.doQuestionSubmit(questionSubmitAddRequest, loginUser);
    //
    //    return ResultUtils.success(questionSubmitId);
    //}

    /**
     * 分页获取题目提交列表（仅管理员和用户本人）
     *
     * @param questionSubmitQueryRequest
     * @return
     */
    @PostMapping("/list/page")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Page<QuestionSubmitVO>> listQuestionSubmitByPage(@RequestBody QuestionSubmitQueryRequest questionSubmitQueryRequest, HttpServletRequest request) {
        long current = questionSubmitQueryRequest.getCurrent();
        long pageSize = questionSubmitQueryRequest.getPageSize();

        Page<QuestionSubmit> questionSubmitPage = questionSubmitService.page(new Page<>(current,pageSize),
                questionSubmitService.getQueryWrapper(questionSubmitQueryRequest));
        final User user = userService.getLoginUser(request);
        Page<QuestionSubmitVO> questionSubmitVOPage = questionSubmitService.getQuestionSubmitVOPage(questionSubmitPage, user);
        return ResultUtils.success(questionSubmitVOPage);
    }



}
